package game.views;

import hx.ui.UIManager;
import game.data.XlsData;
import hx.display.Box;

/**
 * 角色头像渲染组件
 */
@:build(hx.macro.UIBuilder.build("assets/views/RoleHeadImage.xml"))
class RoleHeadImage extends Box {
	public var data:Dynamic;

	override function onInit() {
		super.onInit();
		this.mouseChildren = false;
	}

	public function setData(data:Dynamic):Void {
		this.data = data;
		if (data == null) {
			this.visible = false;
			return;
		}
		this.visible = true;
		var role = XlsData.roles.ofType(data);
		this.head.data = UIManager.getBitmapData("HeadAtlas:" + role.roleid);
		if (this.head.data != null) {
			this.head.width = this.head.data.width - 2;
			this.head.height = this.head.data.height - 1.5;
		}
		this.head.x = this.width / 2 - this.head.width / 2;
		this.head.y = this.height / 2 - this.head.height / 2 - 3;
		// this.head.alpha = 0.5;
	}
}
